package com.example.fw;

import org.netbeans.jemmy.operators.JButtonOperator;
import org.netbeans.jemmy.operators.JDialogOperator;
import org.netbeans.jemmy.operators.JTextFieldOperator;
import org.netbeans.jemmy.operators.JTreeOperator;
import com.example.utils.ListOf;

public class FolderHelper extends HelperBase{
	
	private ListOf<Folder> folders;
	
	public FolderHelper(ApplicationManager manager) {
		super(manager);
	}

	public ListOf<Folder> getFolders() {
		folders = new ListOf<Folder>();
		JTreeOperator tree = new JTreeOperator(mainFrame);
		Object[] children = tree.getChildren(tree.getRoot());
		for (Object child : children) {
			String name = "" + child;
			folders.add(new Folder().withName(name));
		}
		return folders;
	}

	public String createFolder(Folder folder) {
		manager.getMenuHelper().pushCreateFolder();
		JDialogOperator dialog = new JDialogOperator(mainFrame);
		new JTextFieldOperator(dialog).setText(folder.getName());
		new JButtonOperator(dialog,"OK").push();
		return waitMassageDialog("Warning", 3000);
	}

	public void deleteFolder(int index) {
		selectFolderByIndex(index);
		manager.getMenuHelper().pushDeleteFolder();
		JDialogOperator dialog = new JDialogOperator(mainFrame);
		new JButtonOperator(dialog,"Yes").push();
	}

	private void selectFolderByIndex(int index) {
		folders = new ListOf<Folder>();
		JTreeOperator tree = new JTreeOperator(mainFrame);
		tree.selectRow(index);
	}
}
